15 openstreetmap
Downloading OpenStreetMap data with a single line of code
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install geopandas osmnx leafmap
# !pip install geopandas osmnx leafmap
In [2]:
Copied!
import leafmap
import leafmap
Add OSM data of place(s) by name or ID to the map. Note that the leafmap custom layer control does not support GeoJSON, we need to use the ipyleaflet built-in layer control.
In [3]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("New York City", layer_name='NYC')
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("New York City", layer_name='NYC')
m
Out[3]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [4]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("Chicago, Illinois", layer_name='Chicago, IL')
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_geocode("Chicago, Illinois", layer_name='Chicago, IL')
m
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add OSM entities within boundaries of geocodable place(s) to the map.
In [5]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
m.add_osm_from_place(place, tags, layer_name="Los Angeles, CA")
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
place = "Bunker Hill, Los Angeles, California"
tags = {"building": True}
m.add_osm_from_place(place, tags, layer_name="Los Angeles, CA")
m
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/utils_geo.py:335: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. for polygon in geometry: /opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/geometries.py:816: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. for merged_inner_linestring in list(merged_inner_linestrings): /opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/geometries.py:816: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. for merged_inner_linestring in list(merged_inner_linestrings): /opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/utils_geo.py:426: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. for poly in multipoly:
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Show OSM feature tags.
In [6]:
Copied!
# leafmap.osm_tags_list()
# leafmap.osm_tags_list()
Add OSM entities within some distance N, S, E, W of address to the map.
In [7]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={"amenity": "bar"},
dist=1500,
layer_name="NYC bars")
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={"amenity": "bar"},
dist=1500,
layer_name="NYC bars")
m
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/utils_geo.py:335: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. for polygon in geometry: /opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/utils_geo.py:426: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. for poly in multipoly:
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [8]:
Copied!
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={
"landuse": ["retail", "commercial"],
"building": True
},
dist=1000, layer_name="NYC buildings")
m
m = leafmap.Map(toolbar_control=False, layers_control=True)
m.add_osm_from_address(
address="New York City",
tags={
"landuse": ["retail", "commercial"],
"building": True
},
dist=1000, layer_name="NYC buildings")
m
/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/utils_geo.py:335: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. for polygon in geometry: /opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/geometries.py:816: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. for merged_inner_linestring in list(merged_inner_linestrings): /opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/geometries.py:816: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. for merged_inner_linestring in list(merged_inner_linestrings): /opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/osmnx/utils_geo.py:426: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. for poly in multipoly:
Out[8]:
Make this Notebook Trusted to load map: File -> Trust Notebook